package com.qingke.hibernate.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.query.Query;

import com.qingke.hibernate.bean.Accommodation;

public class AccommodationDAO extends SystemDAO{

	public AccommodationDAO(Session session) {
		super(session);
	}
	public List<Accommodation> list(){
		Query<Accommodation> query=session.createQuery("from Accommodation", Accommodation.class);
		return query.getResultList();
	}
	public Accommodation getAccommodationById(int id){
		Query<Accommodation> query=session.createQuery("from Accommodation where id=:id", Accommodation.class);
		query.setParameter("id", id);
		return query.getSingleResult();
	}
	public Accommodation getAccommodationByApartmentId(int apartmentId){
		Query<Accommodation> query=session.createQuery("from Accommodation where apartment_id=:apartmentId", Accommodation.class);
		query.setParameter("apartmentId", apartmentId);
		return query.getSingleResult();
	}
}
